# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgbase=gpgme
pkgname=('libgpgme' 'libgpgme-devel' 'libgpgme-python2' 'libgpgme-python3')
pkgver=1.11.1
pkgrel=1
pkgdesc="A C wrapper library for GnuPG"
arch=('i686' 'x86_64')
url="https://gnupg.org/related_software/gpgme/"
license=('LGPL')
depends=('libassuan' 'libgpg-error' 'gnupg')
makedepends=('libassuan-devel' 'libgpg-error-devel' 'python2' 'python3' 'swig')
options=('!libtool' '!emptydirs')
source=(https://gnupg.org/ftp/gcrypt/${pkgbase}/${pkgbase}-${pkgver}.tar.bz2{,.sig}
        gpgme-1.4.2-msys2.patch)
sha256sums=('2d1b111774d2e3dd26dcd7c251819ce4ef774ec5e566251eb9308fa7542fbd6f'
            'SKIP'
            '7e9157aaebdc04fbf02d2470fc25d730fc873ec402bfb9f7be18501264d076f7')

prepare() {
  cd ${srcdir}/${pkgbase}-${pkgver}
  patch -p1 -i ${srcdir}/gpgme-1.4.2-msys2.patch

  autoreconf -ivf
}

build() {
  cd ${srcdir}/${pkgbase}-${pkgver}
  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --build=${CHOST} \
    --disable-gpgsm-test \
    --disable-gpgconf-test \
    --disable-g13-test \
    --enable-shared \
    --enable-static \
    --enable-fixed-path="/usr/bin:/bin:/usr/sbin:/usr/local/bin"

  make no_undefined=-no-undefined
  make DESTDIR=${srcdir}/dest install
}

check() {
  cd ${srcdir}/${pkgbase}-${pkgver}
  #make check
}

package_libgpgme() {
  groups=('libraries')
  install=${pkgname}.install

  mkdir -p ${pkgdir}/usr/{bin,share}
  cp -f ${srcdir}/dest/usr/bin/*.exe ${pkgdir}/usr/bin/
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
  #cp -rf ${srcdir}/dest/usr/share/doc ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/info ${pkgdir}/usr/share/
}

package_libgpgme-devel() {
  pkgdesc="libgpgme headers and libraries"
  groups=('development')
  depends=("libgpgme=${pkgver}" 'libassuan-devel' 'libgpg-error-devel')
  options=('staticlibs')

  mkdir -p ${pkgdir}/usr/{bin,lib,share}
  cp -f ${srcdir}/dest/usr/bin/*-config ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib/cmake ${pkgdir}/usr/lib/
  cp -f ${srcdir}/dest/usr/lib/*.a ${pkgdir}/usr/lib/
  cp -rf ${srcdir}/dest/usr/share/aclocal ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/common-lisp ${pkgdir}/usr/share/
}

package_libgpgme-python2() {
  pkgdesc="libgpgme bindings for Python2"
  groups=('development')
  depends=("libgpgme=${pkgver}" "python2")
  options=('staticlibs')

  mkdir -p ${pkgdir}/usr/lib
  cp -rf ${srcdir}/dest/usr/lib/python2.7 ${pkgdir}/usr/lib/
}

package_libgpgme-python3() {
  pkgdesc="libgpgme bindings for Python3"
  groups=('development')
  depends=("libgpgme=${pkgver}" "python3")
  options=('staticlibs')

  mkdir -p ${pkgdir}/usr/lib
  cp -rf ${srcdir}/dest/usr/lib/python3.6 ${pkgdir}/usr/lib/
}